package com.example.demopublish.dto;

import com.example.demopublish.consts.FinalValue;
import lombok.Data;

/**
 * @Author: Lxy
 * @Date: 2020/12/29 14:45
 */
@Data
public class ResponseData<T> {

    private int ret;

    private String msg;

    private int status;

    private String requestId;

    private T data;

    public boolean isOk() {
        return FinalValue.CODE_OK == this.ret;
    }

    public static <T> ResponseData ok(T data) {
        ResponseData result = new ResponseData();
        result.setRet(FinalValue.CODE_OK);
        result.setMsg(FinalValue.MSG_SUCCESS);
        result.setData(data);
        return result;
    }

    public static <T> ResponseData ok() {
        ResponseData result = new ResponseData();
        result.setRet(FinalValue.CODE_OK);
        result.setMsg(FinalValue.MSG_SUCCESS);
        result.setData(FinalValue.MSG_SUCCESS);
        return result;
    }
    /*public static <T> ResponseData ok(Map map) {
        ResponseData result = new ResponseData();
        result.setRet(FinalValue.CODE_OK);
        result.setMsg(String.valueOf(map.get("msg")));
        result.setData(map);
        return result;
    }*/

    public static <T> ResponseData error(T data) {
        ResponseData result = new ResponseData();
        result.setRet(FinalValue.CODE_FAILED);
        result.setMsg(FinalValue.MSG_FAIL);
        result.setData(data);
        return result;
    }
}
